package cate.game.log;

import cate.game.GameBody;
import org.slf4j.Logger;

import java.util.HashMap;
import java.util.Map;

public class GameLoggerFactory {
    static final Map<Integer, Map<String, GameSrvLogger>> loggersMap = new HashMap<>();

    public static Logger getLogger(GameBody game, Class<?> clazz){
        Map<String, GameSrvLogger> loggers;
        synchronized (loggersMap){
            if(loggersMap.containsKey(game.config.srvId)) {
                loggersMap.putIfAbsent(game.config.srvId, new HashMap<>());
                loggers = loggersMap.get(game.config.srvId);
            }else {
                loggers = new HashMap<>();
            }
            if(!loggers.containsKey(clazz.getName())) {
                loggers.put(clazz.getName(), new GameSrvLogger(game, clazz.getName()));
            }
        }
        loggersMap.put(game.config.srvId, loggers);
        return loggers.get(clazz.getName()).raw();
    }
}
